package com.ruoyi.web.controller.admin.construction;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.dto.ConstructionWarningQueryDTO;
import com.ruoyi.system.service.IConstructionWarningService;
import com.ruoyi.system.vo.ConstructionWarningOverviewVO;
import com.ruoyi.system.vo.ConstructionWarningVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 施工预警管理控制器
 * 
 * @author ruoyi
 * @since 2024-01-01
 */
@RestController
@RequestMapping("/admin/construction/warning")
@Api(tags = "施工预警管理")
public class ConstructionWarningController extends BaseController {

    @Resource
    private IConstructionWarningService warningService;

    /**
     * 获取预警总览数据
     */
    @PostMapping("/overview")
    @ApiOperation("获取预警总览数据")
//    @PreAuthorize("@ss.hasPermi('construction:warning:overview')")
    public AjaxResult getWarningOverview(@RequestBody(required = false) ConstructionWarningQueryDTO queryDTO) {
        ConstructionWarningOverviewVO overview = warningService.getWarningOverview(queryDTO);
        return AjaxResult.success(overview);
    }

    /**
     * 分页查询预警列表
     */
    @PostMapping("/list")
    @ApiOperation("分页查询预警列表")
//    @PreAuthorize("@ss.hasPermi('construction:warning:list')")
    public TableDataInfo getWarningList(@RequestBody ConstructionWarningQueryDTO queryDTO) {
        startPage();
        List<ConstructionWarningVO> list = warningService.getWarningList(queryDTO);
        return getDataTable(list);
    }

    /**
     * 获取预警详情
     */
    @GetMapping("/detail")
    @ApiOperation("获取预警详情")
//    @PreAuthorize("@ss.hasPermi('construction:warning:query')")
    public AjaxResult getWarningDetail(@RequestParam Long projectId, 
                                      @RequestParam String warningType, 
                                      @RequestParam Long businessId) {
        ConstructionWarningVO detail = warningService.getWarningDetail(projectId, warningType, businessId);
        return AjaxResult.success(detail);
    }

    /**
     * 获取预警统计数据
     */
    @GetMapping("/statistics")
    @ApiOperation("获取预警统计数据")
//    @PreAuthorize("@ss.hasPermi('construction:warning:statistics')")
    public AjaxResult getWarningStatistics() {
        List<ConstructionWarningOverviewVO.WarningStatisticsCardVO> statistics = warningService.getWarningStatistics();
        return AjaxResult.success(statistics);
    }

    /**
     * 获取预警趋势数据
     */
    @GetMapping("/trend")
    @ApiOperation("获取预警趋势数据")
//    @PreAuthorize("@ss.hasPermi('construction:warning:trend')")
    public AjaxResult getWarningTrendData(@RequestParam(required = false) String warningType) {
        List<ConstructionWarningOverviewVO.WarningTrendDataVO> trendData = warningService.getWarningTrendData(warningType);
        return AjaxResult.success(trendData);
    }

    /**
     * 获取预警类型选项
     */
    @GetMapping("/warning-type-options")
    @ApiOperation("获取预警类型选项")
    public AjaxResult getWarningTypeOptions() {
        List<Object> options = warningService.getWarningTypeOptions();
        return AjaxResult.success(options);
    }

    /**
     * 获取预警等级选项
     */
    @GetMapping("/warning-level-options")
    @ApiOperation("获取预警等级选项")
    public AjaxResult getWarningLevelOptions() {
        List<Object> options = warningService.getWarningLevelOptions();
        return AjaxResult.success(options);
    }

    /**
     * 获取处理状态选项
     */
    @GetMapping("/status-options")
    @ApiOperation("获取处理状态选项")
    public AjaxResult getStatusOptions() {
        List<Object> options = warningService.getStatusOptions();
        return AjaxResult.success(options);
    }
}
